package algorithm.sort;

/**
 * @author xutao
 * created 2020/3/16 11:47
 * 选择排序法
 */
public class SelectionSort implements Sort {
    @Override
    public String name() {
        return "选择排序";
    }

    @Override
    public void sort(Integer[] arr) {
        for (int i = 0; i < arr.length-1; i++) {
            int minIndex = i;
            for (int j = i+1; j <arr.length ; j++) {
                if (arr[minIndex]>arr[j]){
                    minIndex = j;
                }
            }
            if (minIndex!=i){
                swap(arr,i,minIndex);
            }
        }
    }
}
